#include "CStoryCellTableWidget.h"

CStoryCellTableWidget::CStoryCellTableWidget(QWidget *parent): QWidget(parent), ui(new Ui::CStoryCellTableWidgetClass())
{
	ui->setupUi(this);
	m_pTableWidget = new QTableWidget(this);
	m_pTableWidget->setGeometry(0, 0, 530, 1200);
	m_pTableWidget->horizontalHeader()->setHidden(true);
	m_pTableWidget->verticalHeader()->setHidden(true);
	m_pTableWidget->setColumnCount(2);
	m_pTableWidget->setStyleSheet("QTableView::item { margin-right: 10px; padding-top: 10px; padding-bottom: 10px; }"
		"QTableWidget::item:selected{background-color: transparent;}");

	m_pTableWidget->horizontalHeader()->setDefaultSectionSize(510 / 2);
	m_pTableWidget->verticalHeader()->setDefaultSectionSize(300);
}

CStoryCellTableWidget::~CStoryCellTableWidget()
{
	delete ui;
}

void CStoryCellTableWidget::SetUi(const QVector<CStoryCellData*>& kqVt, const QObject* kpMiniApp)
{
	int n = kqVt.size();
	m_pTableWidget->setRowCount(n / 2 + n % 2);
	for (int i = 0; i < n; i++)
	{
		CStoryCellWidget* pStoryCellWidget = new CStoryCellWidget;
		pStoryCellWidget->SetUi(kqVt[i]);
		connect(pStoryCellWidget, SIGNAL(StoryCellClick(CStoryCellData*)), kpMiniApp, SLOT(OnStoryCellCarouseImageClick(CStoryCellData*)));
		m_pTableWidget->setCellWidget(i >> 1, i & 1, pStoryCellWidget);
	}
}